package lib.bone.admin.controller.nepu;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.access.module.oss.NepuResearchFileService;
import lib.bone.access.module.oss.domain.NepuResearchFile;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.oss.domain.entity.FileEntity;
import lib.bone.oss.service.impl.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("nepu/research")
@Api(tags = "科研附件")
public class NepuResearchFileController {
    @Autowired
    NepuResearchFileService researchFileService;
    @Autowired
    FileService fileService;


    /**
     * 获取某科研记录绑定的文件
     */
    @GetMapping("file")
    @ApiOperation(value = "查询科研附件")
    public ResponseDTO getResearchFile(@RequestParam("researchType") String researchType,
                                       @RequestParam("mapperId") String mapperId){
        List<NepuResearchFile> researchFiles = researchFileService.getList(researchType,mapperId);
        List<String> fileIds = new ArrayList<>();
        for (NepuResearchFile file:researchFiles){
            fileIds.add(file.getFileId());
        }
        List<FileEntity> files = fileService.getFileList(fileIds);
        return ResponseDTO.succData(files);
    }
}
